﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace PrototypeZGame
{
    public abstract class Actor
    {
        public Vec2 position;
        public string name;

        protected World world;
        protected Texture2D tileset;
        protected int fieldResolution;
        protected Terrain terrain;
        public TileType tileType;
        public string description;

        public Actor(int x, int y, World world)
        {
            position.x = x;
            position.y = y;
            this.world = world;
            fieldResolution = world.fieldResolution;
            terrain = world.terrain;
            _moveCost = 0;
        }

        public Vector2 worldPosition
        {
            get { return new Vector2(-position.x * fieldResolution, -position.y * fieldResolution); }
            set { }
        }

        protected Result _blocking;

        public virtual Result blocking
        {
            get
            {
                return _blocking;
            }
            set
            {
            }
        }

        protected int _moveCost;

        public virtual int moveCost
        {
            get
            {
                return _moveCost;
            }

        }

        public Rectangle destinationRectangle
        {
            get
            {
                return new Rectangle(position.x * fieldResolution, position.y * fieldResolution, fieldResolution, fieldResolution);
            }
        }

        public Rectangle sourceRectangle
        {
            get
            {
                return new Rectangle(((int)tileType % 16) * fieldResolution, fieldResolution * ((int)tileType / 16), fieldResolution, fieldResolution);
            }
        }

        public virtual void Draw()
        {
            world.spriteBatch.Draw(tileset, destinationRectangle, sourceRectangle, Color.White);
        }

        public virtual void move(int x, int y)
        {
            terrain.takeFrom(this);
            position.x += x;
            position.y += y;
            terrain.putOn(this);
        }

        public virtual void move(Vec2 v)
        {
            terrain.takeFrom(this);
            position += v;
            terrain.putOn(this);
        }

        public virtual void moveTo(Vec2 v)
        {
            terrain.takeFrom(this);
            position = v;
            terrain.putOn(this);
        }


    }
}
